// ObjectGenerator.h: interface for the ObjectGenerator class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_OBJECTGENERATOR_H__F60A48CF_B3A3_4D3C_9B63_5C396F0E0EA0__INCLUDED_)
#define AFX_OBJECTGENERATOR_H__F60A48CF_B3A3_4D3C_9B63_5C396F0E0EA0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

template<class ObjectStyle> class ObjectGenerator 
{
public:
	ObjectGenerator(){m_nQuoteCount++;};

	virtual ~ObjectGenerator(){
		m_nQuoteCount--;
		if(m_nQuoteCount == 0)
		{
			delete m_pObject;
			m_pObject = NULL;
		}
	};

	ObjectStyle* Generate(){
		if(m_pObject == NULL)
		{
			m_pObject = new ObjectStyle;
		}
		return m_pObject;
	}

private:
	static ObjectStyle* m_pObject;
	static INT m_nQuoteCount;
};

template<class ObjectStyle> ObjectStyle* ObjectGenerator<ObjectStyle>::m_pObject = NULL;
template<class ObjectStyle> INT ObjectGenerator<ObjectStyle>::m_nQuoteCount = 0;
#endif // !defined(AFX_OBJECTGENERATOR_H__F60A48CF_B3A3_4D3C_9B63_5C396F0E0EA0__INCLUDED_)
